<?php //pack11class

class MainBody extends Module {

    public $cssfile="";
    public $jsfile="";
    public $footer="";
    public $scripts="";
    public $traceEnabled=true;
    public $language=0;
    public $home_state="";
    public $third_party_js="";

    public function setup() {
        $this->home_state=MD5("start");
        $userin=SettingsManager::getSetting("userin");
        $adm=false;
        if($userin) {
        $adm=($userin->value)? true:false;
        if(array_key_exists("preview",$_GET)) $adm=false;
        if(array_key_exists("exit", $_GET)) {
            $_SESSION["userin"]=0;
            trace("userin before:".$_SESSION["userin"]);
            session_unregister('userin');
            unset($_SESSION["userin"]);
            $_COOKIE["userin"]=false;
            $adm=false;
            SettingsManager::setSetting("userin", false);
        }
        } else {
           if(array_key_exists("userin",$_SESSION)) {
            session_unregister('userin');
            unset($_SESSION["userin"]);
            $_COOKIE["userin"]=false;
           } 
        }

        if(array_key_exists("userin", $_SESSION)) {
            trace("userin after:".$_SESSION["userin"]);
        }

        $tracer=new Tracer;
        $this->cssfile="?css=".((array_key_exists("css",$_SESSION))? $_SESSION["css"]:"css");
        $this->jsfile="?js=".((array_key_exists("js",$_SESSION))? $_SESSION["js"]:"js"); //$_SESSION["js"];
        $this->language=LanguagesManager::current();

        $this->addChild(new PostForm);

        $spacer=new Spacer;
        $spacer->setClass("TopSpacer");
        $this->addChild($spacer);
        $this->addChild(($adm)? new MainAdminBlock:((array_key_exists("admin", $_GET))? new Login:new MainBlock));
        $prop_object=SettingsManager::getSetting("object");
        $is_object=(get_class($prop_object)=="Setting")? $prop_object->value:false;
        $prop_admin=SettingsManager::getSetting("userin");
        $is_admin=(get_class($prop_admin)=="Setting")? $prop_admin->value:false;
        if($is_object && $is_admin) {
            $this->third_party_js.=str_replace('\"', '"',"<SCRIPT type=\"text/javascript\" src=\"".pack11."ckeditor/ckeditor.js\"></SCRIPT>");
        }

        $this->addChild(new MainMenu);
        $this->addChild(new History);

        /*if(array_key_exists("dekaro_master", $_COOKIE)) {
            $cookie=$_COOKIE["dekaro_master"];
            MySQLGet::process("Select `id` from ".MySQL::TABLE_USERS." where `cookie`='".$cookie."' limit 1");
            if(MySQLGet::$cc==1) {
                $this->addChild(new TopPanel($adm));
            }
        } else {
            //$this->addChild(new TopPanel("under"));
        }*/

        $this->addChild(new TopPanel($adm));

        $leftBlock=new LeftBlock;

        $popup=new PopupBody;
        if($adm) {
            $leftBlock->addChild(new AdminLeftMenu);

            $popup->addChild(new NewValuePopup);
            $popup->addChild(new NewTextPopup);
            $popup->addChild(new NewPropertyPopup);
            $popup->addChild(new UploadImagePopup);
        } else {
            $leftBlock->addChild(new LeftMenu);
            $leftBlock->addChild(new LeftMenuAll);
            $leftBlock->addChild(new SmallContactsBlock);

            $this->addChild(new SearchBlock);
            $this->addChild(new RightBlock);
            $popup->addChild(new TablePropertiesPopup);
            $object=SettingsManager::getSetting("object");
            if(is_numeric($object->value)) {
                $popup->addChild(new VisitObjectPopup);
                $popup->addChild(new ZoomPhotoPopup);
            }
        }

        $this->addChild($leftBlock);
        $this->addChild(new FooterBlock);

        $this->popups=Template::html($popup);

        SettingsManager::traceAllSettings();
        PropertiesManager::traceAllProperties();

        if(Tracer::$enabled && (getenv("REMOTE_ADDR")=="83.99.163.73" || getenv("REMOTE_ADDR")=="127.0.0.1")) $this->addChild($tracer);

        $object=SettingsManager::getSetting("object");
        if(is_numeric($object->value)) $this->scripts=Template::html(new GoogleMapsScript);
        
        echo Template::html($this);
        //$_SESSION["js"]=MD5(rand(0,9999));
        //$_SESSION["css"]=MD5(rand(0,9999));
    }

}

?>
